<!DOCTYPE html>
<html>
<head>
    <meta content="text/html" charset="UTF-8">
    <title>jQuery EasyUI Demo</title>
    <link rel="stylesheet" type="text/css" href="css/themes/bootstrap/easyui.css">
    <link rel="stylesheet" href="css/themes/icon.css"/>
    <link rel="stylesheet" href="css/themes/color.css"/>
    <link rel="stylesheet" type="text/css" href="css/mycss.css"/>
    <script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="js/jquery.easyui.min.js"></script>
</head>
<body>
<div class="easyui-layout" fit="true">
    <div data-options="region:'west',title:'微信菜单',split:true,border:true" style="width: 160px;padding: 5px">
        <ul id="weixin_menu_tree"></ul>
    </div>
    <div data-options="region:'center',split:true,border:false">
        <table id="weixin_mews_msg"></table>
    </div>
    <div data-options="region:'east',split:true,border:false" style="width: 580px">
        <table id="weixin_mews_msgitem"></table>
    </div>
</div>
<div style="display: none">
    <div id="news_msg_add_win">
        <form id="news_msg_add_from" method="post">
            <div>
                <label for="_1">标题:</label>
                <input  class="easyui-textbox"  id="_1" name="name" data-options="required:true,width:300"/>
            </div>
            <div>
                <label for="news_msg_des">描述:</label>
                <input class="easyui-textbox" id="news_msg_des" type="text" name="html" data-options="required:true,multiline:true,width:400,height:100" />

            </div>
            <div>
                <label for="news_msg_item">条目:</label>
                <input id="news_msg_item" name="item"/>
            </div>
            <a id="news_form_savebtn" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-save'">保存</a>
        </form>
    </div>
    <div id="weixin_newsmsg_add_win" style="padding: 1px">
        <div id="weixin_newsmsg_add_tabs" data-options="width:500,fit:true">
            <div title="添加已有消息" style="padding:20px;display:none;">
                tab1
            </div>
            <div title="添加外链消息" data-options="closable:true" style="overflow:auto;padding:20px;display:none;">
                tab2
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var $=$||{};
    var $weixin_menu_tree=$('#weixin_menu_tree');
    var $weixin_mews_msg=$('#weixin_mews_msg');
    var $news_msg_add_win=$('#news_msg_add_win');
    var $news_msg_add_from=$('#news_msg_add_from');
    var $news_msg_item=$('#news_msg_item');
    var $weixin_newsmsg_add_tabs=$('#weixin_newsmsg_add_tabs');
    var $weixin_newsmsg_add_win=$('#weixin_newsmsg_add_win');

    var btn3=$("<a href='javascript:btnss()'>你好</a>").linkbutton({iconCls:'icon-search',plain:true}).prop('outerHTML');
    var $weixin_mews_msgitem=$('#weixin_mews_msgitem');
    $weixin_newsmsg_add_tabs.tabs({

    });
    $news_msg_add_win.window({
        width:600,
        height:400,
        draggable:true,
        closed : true,
        onOpen:function(){
        }
    });
    $news_msg_add_from.form({
        fit:true,
        width:500,
        url: 'data/test.json',
        onSubmit: function (){
            return true;
        },
        success: function (data) {
            console.log(data);
            alert(data.success);
        }
    });
    $.parser.parse($news_msg_add_from);
    var newsitemindex=-1;
    $weixin_mews_msg.datagrid({
        url:'newsitem/list',
        saveUrl:'newsitem/api?method=add',
        editUrl: 'newsitem/api?method=update',
        delUrl: 'newsitem/api?method=del',
        toolbar: [
            {
                iconCls: 'icon-add',
                text: '添加',
                handler: function () {
                    //$news_msg_add_win.window('open');
                    $weixin_mews_msg.datagrid('addRow',{
                        "author": "admin",
                        "title": "这是文章1",
                        "description": "这是文章描述"
                    });
                    /* var editIndex = $weixin_mews_msg.datagrid('getRows').length-1;
                    $weixin_mews_msg.datagrid('selectRow', editIndex)
                            .datagrid('beginEdit', editIndex); */
                }
            },
            {
                iconCls:'icon-save',
                text:'接受更改',
                handler:function(){
                    //$weixin_mews_msg.datagrid('acceptChanges');
                    /* var options=$weixin_mews_msg.datagrid('options');
                    $.each(options.edititem,function(i,n){
                        $weixin_mews_msg.datagrid('endEdit',n);
                    });
                    options.edititem=[]; */
                	$weixin_mews_msg.datagrid('RecChange');
                }
            },
            {
                iconCls:'icon-save',
                text:'保存',
                handler:function(){
                    /* var rows=$weixin_mews_msg.datagrid('getChanges');
                    console.log(rows); */
                	$weixin_mews_msg.datagird('SaveData');
                }
            },
            {
                iconCls:'icon-cancel',
                text:'取消更改',
                handler:function(){
                    $weixin_mews_msg.datagrid('rejectChanges');
                }
            },
            {
                iconCls:'icon-remove',
                text:'删除',
                handler:function(){
                    var rows=$weixin_mews_msg.datagrid('getChecked');
                    $.messager.confirm('确认','您确认想要删除'+rows.length+'记录吗？',function(r){
                        if (r){
                            alert('确认删除');
                        }
                    });
                }
            }
        ],
        onClickRow:function(rowIndex, rowData){
            $weixin_mews_msgitem.datagrid('load',{
            	typeid:rowData.id
            })
        },
        onBeforeEdit:function(rowIndex){
            $weixin_mews_msg.datagrid('options').edititem.push(rowIndex);
        },
        onDblClickRow:function(rowIndex){
            $weixin_mews_msg.datagrid('beginEdit',rowIndex);
        },
        columns:[[
            {field:'ck',checkbox:true},
            {field:'id',title:'NewsId'},
            {field:'author',title:'作者'},
            {field:'description',title:'描述',width:210,editor:{type:'textbox',options:{required:true}}},
            {field:'ctime',title:'创建时间',width:80,editor:{type:'datetimebox',options:{required:true}}}
        ]]
    });
    $weixin_menu_tree.tree({
        url: 'newstype/list.json',
        border:true,
        fit: true,
        width:400,
        onClick:function(node){
            console.log(node);
            if($weixin_menu_tree.tree('isLeaf',node.target)){
                $weixin_mews_msg.datagrid('load',{
                    id:node.id
                })
            }else{
                $weixin_menu_tree.tree('toggle',node.target);
            }

        }

    });
    $news_msg_item.combogrid({
        width:500,
        multiple:true,
        panelWidth:500,
        pagination:true,
        idField:'id',
        textField:'title',
        toolbar:'#tb2',
        url:'data/newsmsg_data.json',
        columns: [
            [
                {field:'ck',checkbox:true},
                {field: 'id', title: 'NewsId'},
                {field: 'title', title: '标题', editor: {type: 'textbox', options: {required: true}}},
                {field: 'author', title: '作者'},
                {field: 'description', title: '描述', width: 100},
                {field: 'ctime', title: '创建时间', width: 80, editor: {type: 'datetimebox', options: {required: true}}}
                /*{field: 'btn', title: '操作', formatter: function () {
                 return btn2;
                 }}*/
            ]
        ]
    });
    $weixin_mews_msgitem.datagrid({
        url:'data/newsmsg.json',
        saveUrl:'textmsg/api?method=add',
        editUrl: 'textmsg/api?method=update',
        delUrl: 'textmsg/api?method=del',
        columns:[[
            {field:'ck',checkbox:true},
            {field:'id',title:'NewsId'},
            {field:'title',title:'标题'},
            {field:'description',title:'描述',width:100},
            {field:'picurl',title:'图片链接',width:80},
            {field:'url',title:'文章链接',width:80}
        ]],
        toolbar:[
            {
                iconCls:'icon-add',
                text:'添加',
                handler:function(){
                    //alert('添加');
                    $weixin_newsmsg_add_win.window('open');
                }
            }
        ]
    });
    $weixin_newsmsg_add_win.window({
        width:500,
        height:400,
        closed:true
    })
</script>
</body>
<script type="text/javascript">
    alert("init");
</script>
<script type="text/javascript" src="js/easyui-lang-zh_CN.js"></script>
</html>